# -*- coding: utf-8 -*-

#    OriginDB
#    Copyright (C) 2009  Jason Power <power.jg@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from PyQt4.QtGui import *
from PyQt4 import QtCore

from reactionVisual import ReactionVisual



class ResultsScene(QGraphicsScene):

	padding = 20

	def __init__(self, parent=None):
		QGraphicsScene.__init__(self, parent)

		self.reactionVis = []

		self.currentY = 0

		self.oldSelection = []
		
		self.connect(self, QtCore.SIGNAL("selectionChanged()"), self.newSelection)


	def clear(self):
		self.reactionVis = []
		QGraphicsScene.clear(self)

	def getSelected(self):
		print self.selectedItems()
		return self.selectedItems()


	def addReactions(self, reactions):
		self.clear()
		self.currentY = 0
		for reaction in reactions:
			rVis = ReactionVisual(reaction, readOnly = True)
			self.addItem(rVis)
			rVis.setPos(0, self.currentY)
			self.currentY += self.padding + rVis.boundingRect().height()


	def newSelection(self):
		for item in self.oldSelection:
			item.setSelected(False)
		self.oldSelection = self.selectedItems()
		for item in self.oldSelection:
			item.setSelected(True)

	# keeps the compound drawings from appearing
	def mouseMoveEvent(self, event):
		event.accept()